using IM.Easy.Core.ServiceLifetime;
using IM.Easy.Core.Services;
using IM.Easy.Core.Utils;
using IM.Easy.Infrastructure.Query;
using IM.Easy.Entity.System;
using IM.Easy.SystemServices.Dtos;
using Microsoft.AspNetCore.Routing;

namespace IM.Easy.SystemServices.IServices
{
    public interface IApiPermissionsService : IAppServices<ApiPermissions>
    {

        /// <summary>
        /// 根据 ID 获取实体
        /// </summary>
        /// <param name="id">实体的唯一标识</param>
        /// <returns>获取的实体</returns>
        ApiPermissions GetById(long id);

        /// <summary>
        /// 获取路由信息
        /// </summary>
        /// <param name="path"></param>
        /// <param name="method"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        ApiPermissions GetApi(string path, string method);

        /// <summary>
        /// 优先从缓存中获取
        /// </summary>
        /// <returns></returns>
        List<ApiPermissions> GetPermissions();

        /// <summary>
        /// 获取所有实体
        /// </summary>
        /// <returns>所有实体的列表</returns>
        PageResponse<ApiPermissions> GetPageList(ApiPermissionsQueryDto query);

        /// <summary>
        /// 更新一个已有的实体
        /// </summary>
        /// <param name="entity">更新后的实体</param>
        /// <returns>更新后的实体</returns>
        bool Update(ApiPermissions entity);

        /// <summary>
        /// 根据 ID 删除实体
        /// </summary>
        /// <param name="id">要删除的实体的唯一标识</param>
        /// <returns>操作是否成功</returns>
        bool Delete(params long[] key);

        /// <summary>
        /// 接口扫描，获取差异信息
        /// </summary>
        /// <returns></returns>
        void ScanAndSync();

        /// <summary>
        /// 接口合法性校验
        /// </summary>
        /// <param name="apiPermissions">接口权限实体，包含接口权限相关信息</param>
        /// <param name="msg">用于返回校验结果的详细信息，如校验成功或失败的具体原因</param>
        /// <returns>true 表示校验通过；false 表示校验失败</returns>
        bool Validate(ApiPermissions apiPermissions, out string msg);

        /// <summary>
        /// 接口扫描
        /// </summary>
        List<RouteEndpoint> ScanEndpoint();

        /// <summary>
        /// 获取差异
        /// </summary>
        /// <param name="newData"></param>
        /// <param name="oldData"></param>
        /// <returns></returns>
        DiffApiPermissions Diff(List<ApiPermissions> newData, List<ApiPermissions> oldData);

        /// <summary>
        /// 转化成数据库实体
        /// </summary>
        /// <param name="endpoints"></param>
        /// <returns></returns>
        List<ApiPermissions> Convert(List<RouteEndpoint> endpoints);

        /// <summary>
        /// 设置状态
        /// </summary>
        /// <param name="status"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        int SetStatus(bool status, params long[] ids);

        /// <summary>
        /// 设置日志记录状态
        /// </summary>
        /// <param name="track"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        int SetTrack(bool track, params long[] ids);

        /// <summary>
        /// 获取下拉选项列表
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        List<ApiPermissions> GetOptionList(string keyword);
    }
}
